home *** CD-ROM | disk | FTP | other *** search
- /* Sun-$Revision: 8.1 $ */
-
- # include <stdio.h>
- # include <X11/Xlib.h>
- # include <X11/Xutil.h>
- # include "_glueDefs.c.incl"
- # include "xlib.primMaker.h"
-
- // Display_seal is declared here
- # include "xlibPrims.h"
-
-
- // Display_seal is defined in the VM
- # define xTypeSealsDo(template) \
- template(Foo) \
- template(Atom) \
- template(Colormap) \
- template(Cursor) \
- template(Drawable) \
- template(Font) \
- template(GC) \
- template(Pixmap) \
- template(Screen) \
- template(Visual) \
- template(Window) \
- template(XAnyEvent) \
- template(XButtonEvent) \
- template(XCharStruct) \
- template(XClientMessageEvent) \
- template(XColor) \
- template(XColormapEvent) \
- template(XConfigureEvent) \
- template(XCrossingEvent) \
- template(XEnterWindowEvent) \
- template(XEvent) \
- template(XExposeEvent) \
- template(XFontStruct) \
- template(XGCValues) \
- template(XGraphicsExposeEvent) \
- template(XKeyEvent) \
- template(XImage) \
- template(XLeaveWindowEvent) \
- template(XMapEvent) \
- template(XMotionEvent) \
- template(XNoExposeEvent) \
- template(XReparentEvent) \
- template(XSizeHints) \
- template(XTextProperty) \
- template(XTextProperty_value) \
- template(XUnmapEvent) \
- template(XVisibilityEvent) \
- template(XVisualInfo) \
- template(XWMHints)
-
- # define defineXTypeSeals(stem) \
- char* CONC(stem,_seal) = STR(stem);
-
- xTypeSealsDo(defineXTypeSeals)
-
-
- void XGetGCValues_wrap(Display* display, GC gc, unsigned long valuemask,
- XGCValues *values_return, void* FH) {
- int status = XGetGCValues(display, gc, valuemask, values_return);
- if (status == 0) {
- failure(FH, "XGetGCValues failed--valuemask may be invalid");
- }
- }
-
- int XSetWMProtocol_wrap(Display* display, Window window, Atom protocol) {
- Atom ps[1];
- ps[0] = protocol;
- return XSetWMProtocols(display, window, ps, 1);
- }
-
- void XQueryColors_wrap(Display* display,
- Colormap colormap,
- objVectorOop colors_oop,
- void *FH) {
- XColor** pcolors = (XColor**)colors_oop->convertProxyArray(XColor_seal);
- if (!pcolors) {
- prim_failure(FH, BADTYPEERROR);
- return;
- }
- int32 count = colors_oop->length();
- XColor* colors = NEW_RESOURCE_ARRAY(XColor, count);
- for (int32 i = 0; i < count; i++) {
- colors[i] = *pcolors[i];
- }
- XQueryColors(display, colormap, colors, count);
- for (i = 0; i < count; i++) {
- *pcolors[i] = colors[i];
- }
- }
-
- void XStoreColors_wrap(Display* display, Colormap colormap,
- objVectorOop colors_oop, void *FH) {
- XColor** pcolors = (XColor**)colors_oop->convertProxyArray(XColor_seal);
- if (!pcolors) {
- prim_failure(FH, BADTYPEERROR);
- return;
- }
- int32 count = colors_oop->length();
- XColor* colors = NEW_RESOURCE_ARRAY(XColor, count);
- for (int32 i = 0; i < count; i++) {
- colors[i] = *pcolors[i];
- }
- XStoreColors(display, colormap, colors, count);
- }
-
- void XFillPolygon_wrap(Display* display, Drawable d, GC gc,
- objVectorOop xsOop, objVectorOop ysOop,
- int shape, int mode, void* FH) {
- int32* xs = xsOop->convertIntArray();
- int32* ys = ysOop->convertIntArray();
- if (!xs || !ys) {
- prim_failure(FH, BADTYPEERROR);
- return;
- }
- int n = xsOop->length();
- if (n != ysOop->length()) {
- failure(FH, "different number of x and y coordinates");
- return;
- }
- XPoint points[n];
-
- for (int i = 0; i < n; i++) {
- points[i].x = xs[i];
- points[i].y = ys[i];
- }
-
- XFillPolygon(display, d, gc, points, n, Complex, CoordModeOrigin);
- }
-
- XFontStruct* XLoadQueryFont_wrap(Display* display, char* name, void* FH) {
- XFontStruct* font_struct = XLoadQueryFont(display, name);
- if (font_struct == NULL) {
- failure(FH, "font does not exist");
- return NULL;
- }
- return font_struct;
- }
-
- Atom XClientMessageEvent_atomAt_wrap(XClientMessageEvent* rcvr,
- unsigned int index, void* FH) {
- if ( sizeof(rcvr->data.l[0]) * index
- >= sizeof(rcvr->data.l)) {
- prim_failure(FH, BADINDEXERROR);
- return 0;
- }
- return rcvr->data.l[index];
- }
-
- int XStringToTextProperty_wrap(XTextProperty* textProperty, char* string) {
- return XStringListToTextProperty(&string, 1, textProperty);
- }
-
- int XLookupString_wrap(XKeyEvent* event, char* string, int len) {
- KeySym keysym;
- XComposeStatus composeStatus;
- int n = XLookupString(event, string, len, &keysym, &composeStatus);
- return n;
- }
-
- unsigned int XQueryBestStippleWidth(Display* display, Drawable which_screen,
- unsigned int width, unsigned int height,
- void* FH) {
- unsigned int width_return, height_return;
- if (!XQueryBestStipple(display, which_screen, width, height, &width_return,
- &height_return)) {
- prim_failure(FH, PRIMITIVEFAILEDERROR);
- return 0;
- }
- return width_return;
- }
-
- unsigned int XQueryBestStippleHeight(Display* display, Drawable which_screen,
- unsigned int width, unsigned int height,
- void* FH) {
- unsigned int width_return, height_return;
- if (!XQueryBestStipple(display, which_screen, width, height, &width_return,
- &height_return)) {
- prim_failure(FH, PRIMITIVEFAILEDERROR);
- return 0;
- }
- return height_return;
- }
-
- XVisualInfo* XMatchVisualInfo_wrap(Display* display, int screen, int depth,
- int vclass, void *FH) {
- XVisualInfo* vinfo_return = new XVisualInfo;
- if (!XMatchVisualInfo(display, screen, depth, vclass, vinfo_return)) {
- delete vinfo_return;
- failure(FH, "no matching visual found");
- return NULL;
- }
- return vinfo_return;
- }
-
- int maxCharHeight(XFontStruct* font_struct) {
- return font_struct->max_bounds.ascent + font_struct->max_bounds.descent;
- }
- int maxCharWidth(XFontStruct* font_struct) {
- return font_struct->max_bounds.width;
- }
-
-
- inline void XFree_XSizeHints_wrap(XSizeHints *p) {XFree((char*)p);}
- inline void XFree_XWMHints_wrap (XWMHints *p) {XFree((char*)p);}
-
- inline XEvent* asXEvent(XEvent* e) {return e;}
-
-
- # define XEvent_member_wraps_Do(template) \
- template(XAnyEvent,xany) \
- template(XButtonEvent,xbutton) \
- template(XCirculateEvent,xcirculate) \
- template(XCirculateRequestEvent,xcirculaterequest) \
- template(XClientMessageEvent,xclient) \
- template(XColormapEvent,xcolormap) \
- template(XConfigureEvent,xconfigure) \
- template(XConfigureRequestEvent,xconfigurerequest) \
- template(XCreateWindowEvent,xcreatewindow) \
- template(XCrossingEvent,xcrossing) \
- template(XDestroyWindowEvent,xdestroywindow) \
- template(XErrorEvent,xerror) \
- template(XExposeEvent,xexpose) \
- template(XFocusChangeEvent,xfocus) \
- template(XGraphicsExposeEvent,xgraphicsexpose) \
- template(XGravityEvent,xgravity) \
- template(XKeyEvent,xkey) \
- template(XKeymapEvent,xkeymap) \
- template(XMapEvent,xmap) \
- template(XMapRequestEvent,xmaprequest) \
- template(XMappingEvent,xmapping) \
- template(XMotionEvent,xmotion) \
- template(XNoExposeEvent,xnoexpose) \
- template(XPropertyEvent,xproperty) \
- template(XReparentEvent,xreparent) \
- template(XResizeRequestEvent,xresizerequest) \
- template(XSelectionClearEvent,xselectionclear) \
- template(XSelectionEvent,xselection) \
- template(XSelectionRequestEvent,xselectionrequest) \
- template(XUnmapEvent,xunmap) \
- template(XVisibilityEvent,xvisibility)
-
- # define define_XEvent_member_wrap(type,member) \
- type* CONC3(get_,member,_wrap) (XEvent* e) {return & e->member;}
-
- XEvent_member_wraps_Do(define_XEvent_member_wrap)
-
-
- # define WHAT_GLUE FUNCTIONS
- xlib_glue
- # undef WHAT_GLUE
-